package com.example.demo.controller;

import com.example.comon.domain.R;
import com.example.demo.domain.Bo.RoleMenuBo;
import com.example.demo.domain.RoleMenu;
import com.example.demo.service.IRoleMenuService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/roleMenu")
@Api(value = "roleMenu",tags = "角色菜单控制器")
public class RoleMenuController {

    @Autowired
    private IRoleMenuService roleMenuService;

    @PostMapping("/addRoleMenu")
    public R addRoleMenu(@RequestBody RoleMenuBo bo) {
        RoleMenu roleMenuRes = roleMenuService.getByRoleIdAndMenuId(bo.getRoleId(),bo.getMenuId());
        if(roleMenuRes !=null){
            return R.error("该角色已授权该菜单，请勿重复授权");
        }

        RoleMenu roleMenu = new RoleMenu();
        roleMenu.setMenuId(bo.getMenuId());
        roleMenu.setRoleId(bo.getRoleId());
        roleMenu.setCreateBy(1111L);
        roleMenuService.addRoleMenu(roleMenu);
        return R.success("授权成功");
    }

}
